package com.zz.parkingsystem.controller.inspector;
import com.zz.parkingsystem.entity.Inspector;
import com.zz.parkingsystem.service.InspectorService;
import com.zz.parkingsystem.util.NumberUtil;
import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
/**
 已经全部测完========================================================
 */
@RestController
@RequestMapping("/ins")
public class InspectorController {
    @Autowired
    private InspectorService inspectorService;
    @PostMapping("/loginDo")
    public Result login(@RequestBody Inspector inspector, HttpSession session){
        //根据账号查库里加密后的密码

        boolean result=inspectorService.login(inspector.getInsTel(),inspector.getInsPassword());
        if(result){
            Inspector inspector1 = inspectorService.getselectByPrimaryTel(inspector.getInsTel());
            session.setAttribute("insid",inspector1);
            return ResultGenerator.genSuccessResult(inspector1);
        }else return ResultGenerator.genFailResult("登录失败");

    }
    @PostMapping("")
    public Result add(@RequestBody Inspector inspector){
        boolean phone = NumberUtil.isPhone(inspector.getInsTel());
        if(phone){
            int add = inspectorService.add(inspector);
            if(add>0){
                return ResultGenerator.genSuccessResult("注册成功");
            }else{
                return ResultGenerator.genFailResult("注册失败");
            }
        }
        return ResultGenerator.genFailResult("请输入合法的电话号码");
    }


}
